{extend name="index/public" /}

{block name="content"}
<form class="layui-form" action="" id="searchBox">
    <div class="layui-inline">
        {MyTag:client name="client" /}
    </div>
    <div class="layui-inline">
        <select name="plat" id="plat" lay-filter="plat">
            <option value="">全部（渠道类型）</option>
            <option value="cps">CPS</option>
            <option value="sdk">联运</option>
        </select>
    </div>
    <div class="layui-inline">
        <input type="text" name="date" value="{$date}" id="date" lay-verify="datetime" placeholder="支付时间" autocomplete="off" class="layui-input">
    </div>
    <div class="layui-inline" style="width: 125px;">
        <input type="text" class="layui-input layui-disabled" value="{$date2}" id="date2" placeholder=" - ">
    </div>
    <div class="layui-inline">
        <select name="debug" id="debug" lay-filter="debug">
            <option value="">全部（测试数据）</option>
            <option value="1">测试数据</option>
            <option value="2" selected>非测试数据</option>
        </select>
    </div>
    <div class="layui-inline">
        <div class="layui-input-inline">
            {MyTag:game type='manage' /}
        </div>
    </div>
    <div class="layui-inline">
        <select name="pay_type" id="pay_type" lay-filter="pay_type">
            <option value="">全部（支付方式）</option>
            <option value="wxpay">CPS微信</option>
            <option value="alipay">CPS支付宝</option>
        </select>
    </div>
    <div class="layui-inline">
        <button class="layui-btn my-btn-sm searchBtn my-btn" lay-filter="demo1" lay-submit="">搜索</button>
    </div>
</form>
<div id="toolBox">
    <div class="layui-inline mt4">
        <div class="my-btn my-btn-total">充值总额：<span id="total_price">0.00</span></div>
    </div>
    <div class="layui-inline mt4">
        <button class="layui-btn my-btn my-btn-sm toolBtn" id="export">导出</button>
    </div>
</div>

<table id="tableBox" lay-filter="tableBox"></table>
{/block}

{block name="css"}
{/block}

{block name="js"}
<script>
    layui.use(['form', 'laydate', 'table'], function(){
        var table = layui.table
            ,$ = layui.$
            ,form = layui.form
            ,laydate = layui.laydate
            ,load = null
            ,active = {
                reload: function () {
                    var jsonObj = {
                        "plat": $('#plat').val()
                        ,"date": $('#date').hasClass('layui-disabled') ? $('#date2').val() : $('#date').val()
                        ,"debug": $('#debug').val()
                        ,"game_id": $('#game_id').val()
                        ,"pay_type": $('#pay_type').val()
                        ,"game_server": $('#game_server').find('.my-btn').attr('val')
                        ,"game_publish": $('#game_publish').find('.my-btn').attr('val')
                        ,"game_platform": $('#game_platform').find('.my-btn').attr('val')
                        ,"game_client": $('#game_client').find('.my-btn').attr('val')
                    };

                    table.reload('tableId', {
                        page: {curr: 1}
                        ,where: jsonObj
                        ,height: 'full-145'
                    })
                },
            };

        table.render({
            elem: '#tableBox'
            ,height: 'full-145'
            ,url: '{:url("PayGame/index")}'
            ,where: {date:$('#date').val(), debug:$('#debug').val()}
            ,page: true
            ,limit:20
            ,limits:[20,40,60,80]
            ,loading:true
            ,id:'tableId'
            ,done: function (res, curr, count) {
                $('#total_price').html(res.params);
                layer.close(load);
                $('#layui-loading').hide();
            }
            ,cols: [[
                {field:'daytime', title: '充值日期'}
                ,{field:'game_id', title: '游戏ID', sort:true}
                ,{field:'game_name', title: '游戏名称'}
                ,{field:'total_price', title: '充值金额', sort:true}
            ]]
        });

        //日期
        laydate.render({
            elem: '#date'
            ,type: 'date'
            ,range: true
            ,calendar: true
            ,min: '2016-01-01'
            ,max: 0
            ,ready: function(date){
                $('#date2').addClass('layui-disabled');
                $('#date').removeClass('layui-disabled');
            }
        });

        laydate.render({
            elem: '#date2'
            ,type: 'month'
            ,range: true
            ,min: '2016-01-01'
            ,max: 0
            ,format: 'yyyy-MM'
            ,ready: function(date){
                $('#date').addClass('layui-disabled');
                $('#date2').removeClass('layui-disabled');
            }
        });

        //支付方式
        form.on('select(pay_type)', function(data){
            $('#plat').find('option').eq(1).attr('selected', true);
            form.render('select');
        });

        $('#searchBox .searchBtn').on('click', function(){
            load = layer.load();
            active['reload'].call(this);
            return false;
        });

        $('#toolBox .toolBtn').on('click', function(){
            if($(this).attr('id') == 'export'){
                var jsonStr = ''
                    ,jsonObj = {
                        "plat": $('#plat').val()
                        ,"date": $('#date').hasClass('layui-disabled') ? $('#date2').val() : $('#date').val()
                        ,"debug": $('#debug').val()
                        ,"game_id": $('#game_id').val()
                        ,"pay_type": $('#pay_type').val()
                        ,"game_server": $('#game_server').find('.my-btn').attr('val')
                        ,"game_publish": $('#game_publish').find('.my-btn').attr('val')
                        ,"game_platform": $('#game_platform').find('.my-btn').attr('val')
                        ,"game_client": $('#game_client').find('.my-btn').attr('val')
                        ,"export": true
                    };
                layer.msg('导出中....', {icon: 1, time: 2000});
                for(k in jsonObj){
                    jsonStr += k + '=' + jsonObj[k] + '&';
                }
                window.location.href = '{:url("PayGame/index")}?'+jsonStr.substring(0, jsonStr.length-1);
            }
        });
    });
</script>
{/block}